home *** CD-ROM | disk | FTP | other *** search
- /*-------- Play a sound osax by PAUTEX jf 12/93 ----- */
- /* this file for demo about how to wrire an OSAX for Applescript */
- /* contact by mail for other details
-
- e-mail pautex@lpmi.u-nancy.fr
-
- */
- #include <Aliases.h>
-
- int Sound(int n);
- int SoundN(Str255 nom);
- /********************************* ORIGINE *********************************************/
- pascal main(AppleEvent *theAEvt, AppleEvent *reply, long *theRefCon)
- {
- int i,myErr,nb,pf1,soundID=0;
- DescType returnedType;
- char mynom[256];
- Str255 nom;
- Size actualSize = 0;
- Size dataSize = 4,optionSize;
- Size nomSize = 0,typeSize;
- OSType creator = 'ttxt',filetype = 'TEXT'; /* default */
- FSSpec myFSS;
- long option,ID;
- int currentFile;
- int byname = 0,all = 0;
-
- /* ------------ extraction du ID sound a faire */
- myErr = AEGetParamPtr(theAEvt,'----',typeInteger,&returnedType,&ID,4,&dataSize); /*keyDirectObject*/
- if(!myErr) {
- soundID = ID;
- }
-
- /* ------------ extraction de type du document si present */
- myErr = AEGetParamPtr(theAEvt,'type',typeWildCard,&returnedType,&filetype,4,&typeSize); /*keyDirectObject*/
- if(myErr) {
- filetype = 'TEXT';
- }
-
- /* ------------ extraction du nom du doc a chercher s'il y a lieu */
- myErr = AEGetParamPtr(theAEvt,'name',typeWildCard,&returnedType,&mynom,255,&actualSize); /*keyDirectObject*/
- if(!myErr) {
- for(i=0;i<actualSize;i++) nom[i+1] = mynom[i]; /* deplace chaine */
- nom[0] = actualSize; /* chaine pascal Str255 */
- byname = 1;
- }
-
- /* ------ option de remplacement yes/no */
- myErr = AEGetParamPtr(theAEvt,'alll',typeWildCard,&returnedType,&option,4,&optionSize); /*keyDirectObject*/
- if(!myErr) {
- if (returnedType == 'enum') {
- if (option == 'yes ') all = 1;
- if (option == 'no ') all = 2;
- }
- }
-
- /* ------------ extraction du nom du document a lire si present >> passe in file "hh" */
- myErr = AEGetParamPtr(theAEvt,'fpth',typeFSS,&returnedType,&myFSS,sizeof(myFSS),&nomSize); /*keyDirectObject*/
- if(!myErr) {
- if(returnedType == typeFSS ) { /* realise FSS */
- currentFile = CurResFile();
-
- myErr = FSpOpenRF(&myFSS,fsRdPerm,&pf1);
- if(!myErr) {
- FSpOpenResFile(&myFSS,fsRdPerm);
-
- /* ----- decode les options */
- if(all == 0) {
- if(byname == 0) Sound(soundID); /* par id direct */
- if(byname == 1) SoundN(nom);
- }
- if (all == 1) { /* tt les sons */
- AllSound(0);
-
- }
- if (all == 2) { /* tt les sons */
- AllSound(1);
-
- }
- if(pf1 != 0) CloseResFile(pf1);
- }
- }
- }
-
- /* ------ Pas de fichier specifié passe au systeme direct */
- else {
- UseResFile(0); /* system */
- myErr = 0;
- if(all == 0) {
- if(byname == 0) Sound(soundID); /* par id direct */
- if(byname == 1) SoundN(nom);
- }
- if (all == 1) { /* tt les sons */
- AllSound(0);
-
- }
- if (all == 2) { /* tt les sons */
- AllSound(1);
- }
- }
-
- return myErr;
- }
- /***********************************************************************************************************/
- int Sound(int n) /* un son N° n en res */
- {
- Handle SynthH;
- SynthH = GetResource('snd ',n); /* importe le son N° n */
-
- if(SynthH != nil) {
- SndPlay(0L,SynthH,FALSE);
- ReleaseResource(SynthH);
- }
- }
- /***********************************************************************************************************/
- int SoundN(Str255 nom)
- {
- Handle SynthH;
- SynthH = Get1NamedResource('snd ',nom); /* importe le son N° n */
-
- if(SynthH != nil) {
- SndPlay(0L,SynthH,FALSE);
- ReleaseResource(SynthH);
- }
- }
- /***********************************************************************************************************/
- /* --- tt les son du fichier */
- AllSound(int first)
- {
- Handle SynthH;
- int nb,index;
-
- nb = Count1Resources('snd '); /* nb de son ici */
-
- if(!first) {
- for(index = 1;index <= nb;index++) {
- SynthH = Get1IndResource('snd ',index);
- if(SynthH != nil) {
- SndPlay(0L,SynthH,FALSE);
- ReleaseResource(SynthH);
- }
- }
- }
- else {
- SynthH = Get1IndResource('snd ',1);
- if(SynthH != nil) {
- SndPlay(0L,SynthH,FALSE);
- ReleaseResource(SynthH);
- }
- }
- }
- /***********************************************************************************************************/
-